package ru.averta.notes.domain;

import org.hibernate.search.annotations.Boost;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.annotations.TermVector;
import ru.averta.notes.domain.abstr.AbstractPersistentObject;
import ru.averta.notes.domain.ajax.AjaxCoolMark;
import ru.averta.notes.domain.flags.IAjaxable;

import javax.persistence.*;

/**
 * <code>CoolMark</code>
 *
 * @author fedor.belov (fedor.belov@mail.ru)
 *         Date: 12.09.11 14:50
 */

@Entity
public class CoolMark extends AbstractPersistentObject implements IAjaxable<AjaxCoolMark> {

    /** сдвиг сверху */
    @Column private int top;
    /** сдвиг слева */
    @Column private int left;
    /** что (какой текст) отмечено крутым */
    @Field(store = Store.YES, termVector = TermVector.WITH_POSITION_OFFSETS)
    @Boost(2.0f)
    @Column(columnDefinition="text")
    private String content;
    /** комментарий (опционально) */
    @Field(store = Store.YES, termVector = TermVector.WITH_POSITION_OFFSETS)
    @Boost(2.5f)
    @Column(columnDefinition="text")
    private String comment;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SITE_ID")
    private Site site;

    /** Конструктор по-умолчанию для hibernate */
    public CoolMark() {
    }

    public CoolMark(Site site, int top, int left, String content, String comment) {
        this.top = top;
        this.left = left;
        this.content = content;
        this.comment = comment;
        setSite(site);
    }

    @Override
    public AjaxCoolMark getAjaxObject() {
        return new AjaxCoolMark(top, left, content, comment);
    }

    /* GET / SET */
    public int getTop() {
        return top;
    }

    public void setTop(int top) {
        this.top = top;
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Site getSite() {
        return site;
    }

    public void setSite(Site site) {
        if (this.site != null) this.site.getMarks().remove(this);
        this.site = site;
        this.site.getMarks().add(this);
    }

}
